package com.hanhai.zrb.api.biz.dao.mybatis;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.hanhai.zrb.api.biz.dao.mybatis.base.BaseMapper;
import com.hanhai.zrb.model.intention.Intention;
import com.hanhai.zrb.model.intention.dto.IntentionDto;

/**
 * 
 * IntentionMapper数据库操作接口类
 * 
 **/

public interface IntentionMapper extends BaseMapper {

	/**
	 * 
	 * 查询（根据主键ID查询）
	 * 
	 **/
	Intention selectByPrimaryKey(Long id);
	/**
	 * 
	 * @author ybr
	 * @Title: selectByPrimaryKey 
	 * @Description: 根据Id和用户Id查询
	 * @param id
	 * @param userId
	 * @return Intention
	 */
	Intention selectByIdAndUserId(@Param("id") Long id,@Param("userId") Long userId);
	/**
	 * 
	 * 查询（动态多条件查询）
	 * 
	 **/
	List<Intention> selectAllByCriteria(IntentionDto intentionDto);
	List<Intention> findFundList(IntentionDto intentionDto);
	

	/**
	 * APP分页查询数据
	 */
	List<Intention> selectByMaxId(@Param("userId") Long userId, @Param("maxId") Long maxId,@Param("limit") Integer limit);
	/**
	 * 
	 * 删除（根据主键ID删除）
	 * 
	 **/
	int deleteByPrimaryKey(Long id);

	/**
	 * 
	 * 添加
	 * 
	 **/
	int insert(Intention intention);

	/**
	 * 
	 * 添加 （匹配有值的字段）
	 * 
	 **/
	int insertSelective(Intention intention);

	/**
	 * 
	 * 修改 （匹配有值的字段）
	 * 
	 **/
	int updateByPrimaryKeySelective(Intention intention);

	/**
	 * 
	 * 修改（根据主键ID修改）
	 * 
	 **/
	int updateByPrimaryKey(Intention intention);
	
	/**
	 * 
	 * 根据发布人user id 查询意向
	 * 
	 **/
	List<Intention> selectByUserId(Long userId);
	
	/**
	 * 
	 * @author ybr
	 * @Title: getIntentionsByIds 
	 * @Description: 根据ids查询意向
	 * @param Ids
	 * @return List<Intention>
	 */
	List<Intention> getIntentionsByIds(@Param("ids") List<Long> Ids);
	
	/**
	 * 
	 * @author ybr
	 * @Title: multiDelete 
	 * @Description: 逻辑批量删除
	 * @param idList
	 * @return boolean
	 */
	int multiDelete(List<Long> idList);
	
	/**
	 * 
	 * @author lx
	 * @Title: selectByUserIdAndType 
	 * @Description: 根据用户id和意向类型查询意向
	 * @param userId
	 * @param type
	 * @return List<Intention>
	 */
	List<Intention> selectByUserIdAndType(@Param("userId") Long userId,@Param("type") Integer type);
	
	/**
	 * 
	 * @author ybr
	 * @Title: selectByprojectId 
	 * @Description: 根据项目查询意向
	 * @param projectId
	 * @return List<Intention>
	 */
	@Select("select id, intro, industry, district, amount, mode, type, user_id as userId, pushTime, content, handlePerson, handleTime, status, note, project_id as projectId, auth FROM intention where project_id = #{projectId}")
	List<Intention> selectByprojectId(Long projectId);
	
	/**
	 * 查询用户发有效意向的总数
	 * 
	 * @param userId
	 * @return
	 */
	@Select("select count(1) from intention where user_id= #{userId} and status !=2")
	int countByUid(Long userId);
	
}